package org.footballmanager.pandafootball.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootDanGrading;
import org.footballmanager.pandafootball.system.form.impl.FootDanGradingSearchForm;
import org.footballmanager.pandafootball.system.service.FootDanGradingService;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Service
public class FootDanGradingServiceImpl extends ServiceImpl<FootDanGrading> implements FootDanGradingService {
    /**
     * 查询
     *
     * @param entityname               实体类名
     * @param map                      参数
     * @param footDanGradingSearchForm 条件
     */
    @Override
    public void search(String entityname, Model map, FootDanGradingSearchForm footDanGradingSearchForm) {
        map.addAttribute(String.format(Constants.FORMNAME, entityname), footDanGradingSearchForm);
        Page<FootDanGrading> page = PageHelper.startPage(footDanGradingSearchForm.getPageIndex(), footDanGradingSearchForm.getPageSize());
        List<FootDanGrading> list = this.findall(footDanGradingSearchForm.buildSearchCommond());
        map.addAttribute(Constants.PI, page.toPageInfo());
        map.addAttribute(String.format(Constants.LISTENTITY, entityname), list);
    }

    /**
     * 删除所有
     *
     * @param footDanGradingSearchForm 条件
     * @param request                  请求
     */
    @Override
    public void deleteAll(FootDanGradingSearchForm footDanGradingSearchForm, HttpServletRequest request) {
        if (footDanGradingSearchForm.getSelectIds() != null) {
            String[] result = footDanGradingSearchForm.getSelectIds().split(Constants.COMMA);
            for (String id : result) {
                this.delete(Long.parseLong(id), request);
            }
        }
    }

}
